package com.example.recruitment_website.controller;


import com.example.recruitment_website.domain.Article;
import com.example.recruitment_website.dto.HeadlinesBriefDto;
import com.example.recruitment_website.repository.ArticleRepository;
import com.example.recruitment_website.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("Article")
public class ArticleController {
    @Autowired
    ArticleService articleService;
    @Autowired
    ArticleRepository articleRepository;

    @GetMapping("/article")
    public HashMap findHotKey(){
        List<HeadlinesBriefDto> testList = articleService.findHeadlinesList();
        HashMap<String,Object> map = new HashMap<>();
        map.put("data",testList);
        map.put("msg","请求成功");
        map.put("code",0);
        return map;
    }

    @GetMapping("/findArticleByType")
    public HashMap findArticleByType(Integer type){
        List<HeadlinesBriefDto> testList = articleService.findListByType(type);
        HashMap<String,Object> map = new HashMap<>();
        map.put("data",testList);
        map.put("msg","请求成功");
        map.put("code",0);
        return map;
    }

    @GetMapping("/findArticleById")
    public HashMap findArticleById(Integer id){
        Article article = articleRepository.findById(id);
//        Optional<Article> article = articleRepository.findArticleById(id);
        HashMap<String,Object> map = new HashMap<>();
        map.put("data",article);
        map.put("msg","请求成功");
        map.put("code",0);
        return map;
    }

    @GetMapping("/searchArticleByKey")
    public HashMap findArticleByType(String key){
        List<HeadlinesBriefDto> testList = articleService.searchArticleByKey(key);
        HashMap<String,Object> map = new HashMap<>();
        map.put("data",testList);
        map.put("msg","请求成功");
        map.put("code",0);
        return map;
    }


}
